package com.weifeng.jdsignin;

import com.weifeng.jdsignin.jd.JdChouJingdou;
import com.weifeng.jdsignin.jd.JdPlusSignin;

import com.weifeng.jdsignin.jd.JdSignIn;
import com.weifeng.jdsignin.log.ConfigLog;
import com.weifeng.jdsignin.readexcel.Readuseruntity;
import com.weifeng.jdsignin.readexcel.Useruntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.json.JSONObject;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.List;

/**
 * @description：TODO
 * @USER ：weifeng
 * @date ：2022/11/11 下午 02:26
 */
public class Start extends ConfigLog {
    private static Logger logger = Logger.getLogger(Start.class);


    @Test
    public static void jdplussignin() throws IOException {
        List<Useruntity> userlist = Readuseruntity.read();
            for (Useruntity list : userlist){
                int code = 0;  //状态码
                int maxnumber =  3; //最大重复请求几次
                int number = 1; //从第一次开始请求
                Object errorMessage = "";
                while (code != 200 | errorMessage != null & number <= maxnumber){
                    //判断是不是会员  1代表是会员
                    if (Integer.valueOf(list.getIs_plus()).equals(1)){
                        logger.info("第 "+ number +" 次循环签到。");
                        CloseableHttpResponse httpResponse = JdPlusSignin.plusSignIn(list.getEmail(),
                                list.getPt_pin(),
                                list.getPt_pin(),
                                list.getPt_key());
                        code = httpResponse.getStatusLine().getStatusCode();
                        errorMessage = new JSONObject(EntityUtils.toString(httpResponse.getEntity())).get("errorMessage");
                        logger.info("输出 plus签到结果：" + errorMessage);
                        number++;
                    }else {
                        logger.info("用户 "+list.getPt_pin()+" 不是plus，不执行plus签到！");
                        number = maxnumber+1;
                        code = 200;
                    }
                }
            }
    }

    @Test
    public static void jdchoujingdou() throws IOException{
        List<Useruntity> userlist = Readuseruntity.read();
        for (Useruntity list : userlist){
            JdChouJingdou.jdchoujingdou(list.getEmail(),list.getPt_pin(),list.getPt_pin(),list.getPt_key());
        }
    }

    @Test
    public static void jdsignin() throws IOException{
        List<Useruntity> userlist = Readuseruntity.read();
        for (Useruntity list : userlist){
            JdSignIn.jdsignin(list.getEmail(),list.getPt_pin(),list.getPt_pin(),list.getPt_key());
        }
    }

    @Test
    public static void a(){
        int a = 2;
        String b = "1";
        if (Integer.valueOf(b).equals(a)){
            System.out.println(1111111111);
        }else {
            System.out.println(222222);
        }
    }


}
